package org.afi.mushroomplayer.adapter;

import java.util.List;

import org.afi.mushroomplayer.R;
import org.afi.mushroomplayer.model.SongHolder;
import org.afi.mushroomplayer.model.SongInfo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class SongAdapter extends BaseAdapter {

    private List<SongInfo> mSongList;
    private LayoutInflater mInflater;
    
    public SongAdapter(Context context) {
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    
    public void setListData(List<SongInfo> list) {
        mSongList = list;
    }
    
    @Override
    public int getCount() {
        return mSongList.size();
    }

    @Override
    public Object getItem(int position) {
        return mSongList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        SongHolder holder = null;
        SongInfo info = mSongList.get(position);
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.song_item, null);
            holder = new SongHolder();
            holder.tvTitle = (TextView) convertView.findViewById(R.id.song_title);
            holder.tvSize = (TextView) convertView.findViewById(R.id.song_size);
            holder.tvInfo = (TextView) convertView.findViewById(R.id.song_info);
            convertView.setTag(holder);
        } else {
            holder = (SongHolder) convertView.getTag();
        }
        holder.tvTitle.setText(info.getTitle());
        holder.tvSize.setText(info.getSize());
        holder.tvInfo.setText(info.getAlbum() + " - " + info.getArtist());
        return convertView;
    }

}
